package com.boruan.qq.zxgylibrary.ui.adapters;

import android.app.Activity;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.boruan.qq.zxgylibrary.R;
import com.boruan.qq.zxgylibrary.R2;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 崔琦 on 2019/8/28.
 * des: 发票适配器
 */

public class InvoiceAdapter extends RecyclerView.Adapter<InvoiceAdapter.InvoiceViewHolder> {

    private Activity mContext;

    public InvoiceAdapter(Activity mContext) {
        this.mContext = mContext;
    }

    @NonNull
    @Override
    public InvoiceViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.drug_item_invoice, parent, false);
        return new InvoiceViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final InvoiceViewHolder holder, int position) {
        if (position == 0){
            holder.tvInvoiceType.setText("单位");
            holder.tvInvoiceType.setTextColor(mContext.getResources().getColor(R.color.invoice_color_one));
            holder.tvInvoiceType.setBackgroundResource(R.drawable.drug_shape_invoice_back_one);
            holder.tvEin.setVisibility(View.VISIBLE);

            holder.tvInvoiceTypeName.setText("青岛海联软件科技有限公司");
        }else {
            holder.tvInvoiceType.setText("个人");
            holder.tvInvoiceType.setTextColor(mContext.getResources().getColor(R.color.invoice_color_two));
            holder.tvInvoiceType.setBackgroundResource(R.drawable.drug_shape_invoice_back_two);
            holder.tvEin.setVisibility(View.GONE);

            holder.tvInvoiceTypeName.setText("李女士");
        }

        holder.llClickInvoice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                holder.ivSelector.setImageResource(R.mipmap.drug_pay_select_true);
                Intent intent = new Intent();
                intent.putExtra("invoice",holder.tvInvoiceTypeName.getText().toString());
                mContext.setResult(15,intent);
                mContext.finish();
            }
        });
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    public class InvoiceViewHolder extends RecyclerView.ViewHolder {

        @BindView(R2.id.ll_click_invoice)
        LinearLayout llClickInvoice;
        @BindView(R2.id.iv_selector)
        ImageView ivSelector;
        @BindView(R2.id.tv_invoice_type)
        TextView tvInvoiceType;
        @BindView(R2.id.tv_invoice_type_name)
        TextView tvInvoiceTypeName;
        @BindView(R2.id.tv_ein)
        TextView tvEin;

        public InvoiceViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
